package org.example.controller;

import com.github.pagehelper.PageInfo;
import org.example.entity.CourseRating;
import org.example.service.CourseRatingService;
import org.example.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName CourseRatingController
 * @Description TODO
 * @Author qiuye
 * @Date 2025年08月17日 20:27
 * @Version 1.0
 */
@RestController
@RequestMapping("rate")
public class CourseRatingController {
    @Autowired
    private CourseRatingService courseRatingService;
    @GetMapping("{id}")
    public R getCourseRating(@PathVariable("id") int courseId,
                             @RequestParam(required = false,defaultValue = "1") int page,
                             @RequestParam(required = false,defaultValue = "5") int size) {
        PageInfo<CourseRating> courseRating = courseRatingService.getCourseRating(courseId, page, size);
        return R.ok(courseRating);
    }

    @GetMapping("/{id}/all")
    public R getAllCourseRating(@PathVariable("id") int courseId) {
        List<CourseRating> allCourseRating = courseRatingService.getAllCourseRating(courseId);
        return R.ok(allCourseRating);
    }
}
